<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>编辑视频信息</title>
    <script src="__STATIC__/js/jquery.js"></script>
    <script src="__STATIC__/layui/layui.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table.js"></script>
    <script src="__STATIC__/bootstrap-table/js/bootstrap-table-zh-CN.min.js"></script>
    <script src="__STATIC__/bootstrap-table/js/dropdown.js"></script>
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap-table.min.css">
    <link rel="stylesheet" href="__STATIC__/bootstrap-table/css/bootstrap.css">
    <script type="text/javascript" src="__STATIC__/x-admin/js/xadmin.js"></script>
    <link rel="stylesheet" href="__STATIC__/x-admin/css/font.css">
    <link rel="stylesheet" href="__STATIC__/x-admin/css/xadmin.css">
</head>
<body>
<br>
<a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right" href="javascript:location.replace(location.href);" title="刷新">
    <i class="layui-icon" style="line-height:30px">ဂ</i></a>
    <table class="layui-table">
        <input type="text" hidden value="{$val.id}" id="id">
    <tbody>
    <tr>
        <td >视频名</td>
        <td ><input id="title" type="text" value="{$val.zjtitle}" placeholder="{$val.zjtitle}"></td>
    </tr>
    <tr>
        <td>视频内容</td>
        <td><textarea id="demo" style="display: none;" placeholder="{$val.content}">{$val.content}</textarea></td>
    </tr>
            <button class="layui-btn layui-btn-normal" id="video" value="{$val.url}">上传视频</button>&nbsp;&nbsp;&nbsp;&nbsp;
            <button class="layui-btn" id="photo" value="{$val.icon_path}">上传图片</button>&nbsp;&nbsp;&nbsp;&nbsp;
            <button class="layui-btn layui-btn-warm" id="up">保存</button>&nbsp;&nbsp;&nbsp;&nbsp;
            <button class="layui-btn layui-btn-danger" id="del">删除</button>
    </tbody>
    </table>
</body>
</html>
<script>
    layui.use('layedit', function(){
        var layedit = layui.layedit;
        layedit.build('demo'); //建立编辑器
        layedit.build('demo', {
            tool: ['left', 'center','strong','italic']
        });
    });
</script>
<script>
    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: "#photo",
            url: "{:url('/common/img')}", //接口路径
            method: 'post', //可选项。HTTP类型，默认post
            data: {path:'/public/uploads/bar_video/img'}, //可选项。额外的参数，如：{id: 123, abc: 'xxx'}
            done: function(res){
                if(res.img){
                    //alert(res.img)
                    $("#id").val(res.img)
                    return
                }else{
                    alert(res.code)
                    return
                }
            },
            accept: 'images', //允许上传的文件类型
            size: 4096, //最大允许上传的文件大小
            auto:"true"
        });
    })
    //上传视频
    layui.use('upload', function(){
        var upload = layui.upload;
        upload.render({
            elem: "#video",
            url: "{:url('/common/video')}", //接口路径
            method: 'post', //可选项。HTTP类型，默认post
            data: {path:'/public/uploads/bar_video/video'}, //可选项。额外的参数，如：{id: 123, abc: 'xxx'}
            done: function(res){
                if(res.img){
                    //alert(res.img)
                    $("#video").val(res.img)
                    return
                }else{
                    alert(res.code)
                    return
                }
            },
            accept: 'images', //允许上传的文件类型
            size: 4096, //最大允许上传的文件大小
            auto:"true"
        });
    })
    //修改视频信息
    $("#up").click(function(){
        //视频id
        var id = $("#id").val();
        //视频名称
        var title = $("#title").val();
        //视频介绍
        var content = $("#demo").val();
        //视频图片
        var photo = $("#photo").val();
        //视频
        var video = $("#video").val();


        //视频的分类
        if (!id || !title || !content || !photo || !video){
            layer.msg('请不要输入空白的信息', {icon: 5, time: 2000});
            return;
        }
        $.ajax({
            url: "{:url('/video/updateSection')}",
            data: {id: id, zjtitle: title, content: content, icon_path: photo, url: video},
            type: "post",
            dataType: "json",
            success: function(res){
                if(res.code){
                    layer.msg(res.msg,{icon:1,time:2000},function(){
                        window.location.reload();
                    });
                    return;
                }else{
                    layer.msg(res.msg,{icon:5,time:2000});
                    return;
                }
            }
        })
    })
    //删除视频
    $("#del").click(function(){
        layer.confirm('确认删除此视频？', {
            btn: ['是的','不'] //按钮
        }, function(){
            var id = $("#id").val();
            $.ajax({
                url:"{:url('/video/delBarVideo')}",
                data:{id:id},
                type:"post",
                dataType:"json",
                success:function(res){
                    if(res.code){
                        layer.msg(res.msg,{icon:1,time:2000},function(){
                            window.location.reload();
                        });
                        return;
                    }else{
                        layer.msg(res.msg,{icon:5,time:2000});
                        return;
                    }
                }

            })
        })
    });


</script>